import 'package:abc/controller/alipay_controller.dart';
import 'package:abc/view/CustomAppBar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:qr_flutter/qr_flutter.dart';

class AlipayPage extends GetView<AlipayController> {
  const AlipayPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (!Get.isRegistered<AlipayController>()) {
      Get.lazyPut(() => AlipayController());
    }
    return Scaffold(
      backgroundColor: const Color(0xFF0E0F26), // 深色背景
      appBar: CustomAppBar(
        title: "支付宝",
        onBack: () {
          Get.back();
        },
      ),
      body: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 9.0),
        child: Container(
            height: 547,
            padding: EdgeInsets.only(top: 39),
            decoration: BoxDecoration(
              color: Color(0x33959595),
              borderRadius: BorderRadius.circular(10.0),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                const Text(
                  '支付宝扫码付款',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 18,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                const SizedBox(height: 21),

                // 二维码占位符
                Container(
                  width: 194,
                  height: 194,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(8.0),
                    border: Border.all(color: Colors.white10, width: 1.0),
                  ),
                  // 实际应用中这里会放置二维码图片
                  child:  Center(
                    child: QrImageView(
                      data: '125454545', // 二维码内容
                      version: QrVersions.auto,
                      size: 192.0, // 调整大小以适应内边距
                      gapless: false,
                      errorStateBuilder: (cxt, err) {
                        return const Center(
                          child: Text(
                            '二维码生成失败',
                            style: TextStyle(color: Colors.red),
                          ),
                        );
                      },
                    ),
                  ),
                ),
                const SizedBox(height: 30),

                // 打开支付宝APP继续付款按钮
                SizedBox(
                  height: 40,
                  child: ElevatedButton(
                    onPressed: () {
                      // 实际中调用支付宝APP Schema
                    },
                    style: ElevatedButton.styleFrom(
                      backgroundColor: Color(0xFF1880EF),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10.0),
                      ),
                    ),
                    child: const Text(
                      '打开支付宝APP继续付款',
                      style: TextStyle(
                        fontSize: 15,
                        color: Colors.white,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                  ),
                ),
                const SizedBox(height: 20),

                InkWell(
                  child: Text(
                    '我已付款，返回查看订单',
                    style: TextStyle(
                      color: Colors.white.withOpacity(0.6),
                      fontSize: 14,
                      fontWeight: FontWeight.w400,
                      decorationColor: Colors.white.withOpacity(0.6),
                    ),
                  ),
                  onTap: () {},
                ),
                const SizedBox(height: 66),

                // 底部提示
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Image.asset(
                      'assets/images/ic_scan.png',
                      width: 24,
                      height: 24,
                    ),
                    const SizedBox(width: 8),
                    Text(
                      '请使用支付宝扫一扫\n扫描二维码完成支付',
                      textAlign: TextAlign.left,
                      style: TextStyle(
                        color: Colors.white.withOpacity(0.6),
                        fontSize: 13,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                  ],
                ),
                // const SizedBox(height: 20),
              ],
            ),
          
        ),
      ),
    );
  }
}
